<!DOCTYPE html>
<html lang=en

  >

  <head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5" />
    <meta name="description" content="TOP 1：Timer Timer 是 JDK 自带的定时任务执行类，无论任何项目都可以直接使用 Timer 来实现定时任务，所以 Timer 的优点就是使用方便，它的实现代码如下：   12345678910111213141516public class MyTimerTask &amp;#123;   public static void main(String[] args) &amp;#123;">
<meta property="og:type" content="article">
<meta property="og:title" content="定时任务">
<meta property="og:url" content="https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/index.html">
<meta property="og:site_name" content="一个有温度的小流年">
<meta property="og:description" content="TOP 1：Timer Timer 是 JDK 自带的定时任务执行类，无论任何项目都可以直接使用 Timer 来实现定时任务，所以 Timer 的优点就是使用方便，它的实现代码如下：   12345678910111213141516public class MyTimerTask &amp;#123;   public static void main(String[] args) &amp;#123;">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2023-09-04T09:31:58.000Z">
<meta property="article:modified_time" content="2023-09-04T11:28:28.302Z">
<meta property="article:author" content="小流年">
<meta name="twitter:card" content="summary">
    
    
      
        
          <link rel="shortcut icon" href="/mrl/images/favicon.ico">
        
      
      
        
          <link rel="icon" type="image/png" href="/mrl/images/favicon-192x192.png" sizes="192x192">
        
      
      
        
          <link rel="apple-touch-icon" sizes="180x180" href="/mrl/images/apple-touch-icon.png">
        
      
    
    <!-- title -->
    <title>定时任务</title>
    <!-- async scripts -->
    <!-- Google Analytics -->


    <!-- Umami Analytics -->


    <!-- styles -->
    
<link rel="stylesheet" href="/mrl/css/style.css">

    <!-- persian styles -->
    
    <!-- rss -->
    
    
	<!-- mathjax -->
	
<meta name="generator" content="Hexo 6.3.0"></head>


    <body class="max-width mx-auto px3 ltr">
      
        <div id="header-post">
  <a id="menu-icon" href="#" aria-label="Menu"><i class="fa-solid fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#" aria-label="Menu"><i class="fa-solid fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" aria-label="Top" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fa-solid fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
        <!--
       --><li><a href="/mrl/search/">搜索</a></li><!--
     --><!--
       --><li><a href="/mrl/">首页</a></li><!--
     --><!--
       --><li><a href="/mrl/categories/">个人</a></li><!--
     --><!--
       --><li><a href="/mrl/articles/">归档</a></li><!--
     --><!--
       --><li><a href="/mrl/product/">产品</a></li><!--
     -->
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" aria-label="Previous post" href="/mrl/2023/09/04/Java%E5%A4%9A%E7%BA%BF%E7%A8%8B%E2%80%93%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/"><i class="fa-solid fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" aria-label="Next post" href="/mrl/2023/08/29/%E6%B5%8F%E8%A7%88%E5%99%A8%E8%BE%93%E5%85%A5www.baidu.com%E4%B9%8B%E5%90%8E/"><i class="fa-solid fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" aria-label="Back to top" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fa-solid fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" aria-label="مشاركة المنشور" href="#"><i class="fa-solid fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">Previous post</span>
      <span id="i-next" class="info" style="display:none;">Next post</span>
      <span id="i-top" class="info" style="display:none;">Back to top</span>
      <span id="i-share" class="info" style="display:none;">مشاركة المنشور</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&text=定时任务"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&is_video=false&description=定时任务"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=定时任务&body=Check out this article: https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/"><i class="fa-solid fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&name=定时任务&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&t=定时任务"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    
    
      <div id="toc">
        <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#TOP-1%EF%BC%9ATimer"><span class="toc-number">1.</span> <span class="toc-text">TOP 1：Timer</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Timer-%E7%BC%BA%E7%82%B9%E5%88%86%E6%9E%90"><span class="toc-number">2.</span> <span class="toc-text">Timer 缺点分析</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%A8%8B%E5%BA%8F%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C"><span class="toc-number">3.</span> <span class="toc-text">程序执行结果</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Top-2%EF%BC%9ASpring-Task"><span class="toc-number">5.</span> <span class="toc-text">Top 2：Spring Task</span></a></li></ol>
      </div>
    
  </span>
</div>

          
            <div class="content index py4 ">
              
                    <article class="post h-entry" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle p-name" itemprop="name headline">
        定时任务
    </h1>



    <div class="meta">
      <span class="author p-author h-card" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span class="p-name" itemprop="name">小流年</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2023-09-04T09:31:58.000Z" class="dt-published" itemprop="datePublished">2023-09-04</time>
        
      
    </div>


      
    <div class="article-category">
        <i class="fa-solid fa-archive"></i>
        <a class="category-link" href="/mrl/categories/%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1/">定时任务</a>
    </div>


      

    </div>
  </header>
  

  <div class="content e-content" itemprop="articleBody">
    <h1 id="TOP-1：Timer"><a href="#TOP-1：Timer" class="headerlink" title="TOP 1：Timer"></a>TOP 1：Timer</h1><ul>
<li><p>Timer 是 JDK 自带的定时任务执行类，无论任何项目都可以直接使用 Timer 来实现定时任务，所以 Timer 的优点就是使用方便，它的实现代码如下：</p>
  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">public class MyTimerTask &#123;</span><br><span class="line">   public static void main(String[] args) &#123;</span><br><span class="line">       // 定义一个任务</span><br><span class="line">       TimerTask timerTask = new TimerTask() &#123;</span><br><span class="line">           @Override</span><br><span class="line">           public void run() &#123;</span><br><span class="line">               System.out.println(&quot;Run timerTask：&quot; + new Date());</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;;</span><br><span class="line">       // 计时器</span><br><span class="line">       Timer timer = new Timer();</span><br><span class="line">       // 添加执行任务（延迟 1s 执行，每 3s 执行一次）</span><br><span class="line">       timer.schedule(timerTask, 1000, 3000);</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
<li><p>程序执行结果如下：</p>
 <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Run timerTask：Mon Aug 17 21:29:25 CST 2020</span><br><span class="line"> Run timerTask：Mon Aug 17 21:29:28 CST 2020</span><br><span class="line"> Run timerTask：Mon Aug 17 21:29:31 CST 2020</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="Timer-缺点分析"><a href="#Timer-缺点分析" class="headerlink" title="Timer 缺点分析"></a>Timer 缺点分析</h1><ul>
<li><p>Timer 类实现定时任务虽然方便，但在使用时需要注意以下问题。</p>
</li>
<li><p>问题 1：任务执行时间长影响其他任务</p>
</li>
<li><p>当一个任务的执行时间过长时，会影响其他任务的调度，如下代码所示：</p>
  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">public class MyTimerTask &#123;</span><br><span class="line">   public static void main(String[] args) &#123;</span><br><span class="line">       // 定义任务 1</span><br><span class="line">       TimerTask timerTask = new TimerTask() &#123;</span><br><span class="line">           @Override</span><br><span class="line">           public void run() &#123;</span><br><span class="line">               System.out.println(&quot;进入 timerTask 1：&quot; + new Date());</span><br><span class="line">               try &#123;</span><br><span class="line">                   // 休眠 5 秒</span><br><span class="line">                   TimeUnit.SECONDS.sleep(5);</span><br><span class="line">               &#125; catch (InterruptedException e) &#123;</span><br><span class="line">                   e.printStackTrace();</span><br><span class="line">               &#125;</span><br><span class="line">               System.out.println(&quot;Run timerTask 1：&quot; + new Date());</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;;</span><br><span class="line">       // 定义任务 2</span><br><span class="line">       TimerTask timerTask2 = new TimerTask() &#123;</span><br><span class="line">           @Override</span><br><span class="line">           public void run() &#123;</span><br><span class="line">               System.out.println(&quot;Run timerTask 2：&quot; + new Date());</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;;</span><br><span class="line">       // 计时器</span><br><span class="line">       Timer timer = new Timer();</span><br><span class="line">       // 添加执行任务（延迟 1s 执行，每 3s 执行一次）</span><br><span class="line">       timer.schedule(timerTask, 1000, 3000);</span><br><span class="line">       timer.schedule(timerTask2, 1000, 3000);</span><br><span class="line">   &#125;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="程序执行结果"><a href="#程序执行结果" class="headerlink" title="程序执行结果"></a>程序执行结果</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">进入 timerTask 1：Mon Aug 17 21:44:08 CST 2020</span><br><span class="line">Run timerTask 1：Mon Aug 17 21:44:13 CST 2020</span><br><span class="line">Run timerTask 2：Mon Aug 17 21:44:13 CST 2020</span><br><span class="line">进入 timerTask 1：Mon Aug 17 21:44:13 CST 2020</span><br><span class="line">Run timerTask 1：Mon Aug 17 21:44:18 CST 2020</span><br><span class="line">进入 timerTask 1：Mon Aug 17 21:44:18 CST 2020</span><br><span class="line">Run timerTask 1：Mon Aug 17 21:44:23 CST 2020</span><br><span class="line">Run timerTask 2：Mon Aug 17 21:44:23 CST 2020</span><br><span class="line">进入 timerTask 1：Mon Aug 17 21:44:23 CST 2020</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><ul>
<li>从上述结果中可以看出，当任务 1 运行时间超过设定的间隔时间时，任务 2 也会延迟执行。 原本任务 1 和任务 2 的执行时间间隔都是 3s，但因为任务 1 执行了 5s，因此任务 2 的执行时间间隔也变成了 10s（和原定时间不符）。</li>
<li>使用 Timer 类实现定时任务时，当一个任务抛出异常，其他任务也会终止运行</li>
</ul>
<h1 id="Top-2：Spring-Task"><a href="#Top-2：Spring-Task" class="headerlink" title="Top 2：Spring Task"></a>Top 2：Spring Task</h1><ul>
<li>使用上面定时任务的实现方式，很难实现设定了具体时间的定时任务，比如当我们需要每周五来执行某项任务时，但如果使用 Spring Task 就可轻松的实现此需求</li>
<li>因此，我们需要使用 Spring Task 就可轻松的实现此需求</li>
</ul>
<ol>
<li>以 Spring Boot 为例，实现定时任务只需两步：</li>
<li>开启定时任务；</li>
<li>添加定时任务。</li>
</ol>
<ul>
<li><p>① 开启定时任务</p>
<p>  开启定时任务只需要在 Spring Boot 的启动类上声明 @EnableScheduling 即可，实现代码如下：</p>
  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">@SpringBootApplication</span><br><span class="line">@EnableScheduling // 开启定时任务</span><br><span class="line">public class DemoApplication &#123;</span><br><span class="line">    // do someing</span><br><span class="line">&#125;</span><br><span class="line">   </span><br></pre></td></tr></table></figure>
</li>
<li><p>② 添加定时任务<br>定时任务的添加只需要使用 @Scheduled 注解标注即可，如果有多个定时任务可以创建多个 @Scheduled 注解标注的方法，示例代码如下：</p>
  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">import org.springframework.scheduling.annotation.Scheduled;</span><br><span class="line">import org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line">@Component // 把此类托管给 Spring，不能省略</span><br><span class="line">public class TaskUtils &#123;</span><br><span class="line">    // 添加定时任务</span><br><span class="line">    @Scheduled(cron = &quot;59 59 23 0 0 5&quot;) // cron 表达式，每周五 23:59:59 执行</span><br><span class="line">    public void doTask()&#123;</span><br><span class="line">        System.out.println(&quot;我是定时任务~&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p><strong>注意</strong>：定时任务是自动触发的无需手动干预，也就是说 Spring Boot 启动后会自动加载并执行定时任务。</p>
</li>
<li><p><strong>cron 表达式在线生成地址</strong>：<a target="_blank" rel="noopener" href="https://cron.qqe2.com/">https://cron.qqe2.com/</a></p>
</li>
</ul>

  </div>
</article>



                      
                        <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
        
          <li><a href="/mrl/search/">搜索</a></li>
        
          <li><a href="/mrl/">首页</a></li>
        
          <li><a href="/mrl/categories/">个人</a></li>
        
          <li><a href="/mrl/articles/">归档</a></li>
        
          <li><a href="/mrl/product/">产品</a></li>
        
      </ul>
    </div>

    
    
      <div id="toc-footer" style="display: none">
        <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#TOP-1%EF%BC%9ATimer"><span class="toc-number">1.</span> <span class="toc-text">TOP 1：Timer</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Timer-%E7%BC%BA%E7%82%B9%E5%88%86%E6%9E%90"><span class="toc-number">2.</span> <span class="toc-text">Timer 缺点分析</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%A8%8B%E5%BA%8F%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C"><span class="toc-number">3.</span> <span class="toc-text">程序执行结果</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Top-2%EF%BC%9ASpring-Task"><span class="toc-number">5.</span> <span class="toc-text">Top 2：Spring Task</span></a></li></ol>
      </div>
    

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&text=定时任务"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&is_video=false&description=定时任务"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=定时任务&body=Check out this article: https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/"><i class="fa-solid fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&title=定时任务"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&name=定时任务&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://liushuaijun.gitee.io/mrl/2023/09/04/%E5%AE%9E%E7%8E%B0%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F/&t=定时任务"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fa-solid fa-bars fa-lg" aria-hidden="true"></i> Menu</a>
        
          <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fa-solid fa-list fa-lg" aria-hidden="true"></i> TOC</a>
        
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fa-solid fa-share-alt fa-lg" aria-hidden="true"></i> Share</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fa-solid fa-chevron-up fa-lg" aria-hidden="true"></i> Top</a>
    </div>

  </div>
</div>

                          
                            <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
    
    
    2020-2023
    小流年
  </div>
  <div class="footer-right">
    <nav>
      <ul>
        <!--
       --><li><a href="/mrl/search/">搜索</a></li><!--
     --><!--
       --><li><a href="/mrl/">首页</a></li><!--
     --><!--
       --><li><a href="/mrl/categories/">个人</a></li><!--
     --><!--
       --><li><a href="/mrl/articles/">归档</a></li><!--
     --><!--
       --><li><a href="/mrl/product/">产品</a></li><!--
     -->
      </ul>
    </nav>
  </div>
  
  <div class="busuanzi">
    
      <!-- 不蒜子统计 -->
      <span id="busuanzi_container_site_pv">
        网站总访问量:<span id="busuanzi_value_site_pv"></span>
      </span>
      
     <span class="post-meta-divider">|</span>
      <span id="busuanzi_container_site_uv" style='display:none'>
          本站访客数<span id="busuanzi_value_site_uv"></span>人
      </span>
    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
     
  </div>
</footer>

            </div>
            <!-- styles -->



  <link rel="preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous" onload="this.onload=null;this.rel='stylesheet'"/>


              <!-- jquery -->

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" crossorigin="anonymous"></script>




<!-- clipboard -->

  
    <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.7/clipboard.min.js" crossorigin="anonymous"></script>
  
  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"Copy to clipboard!\">";
    btn += '<i class="fa-regular fa-clone"></i>';
    btn += '</span>';
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "Copied!");
      e.clearSelection();
    })
  })
  </script>


<script src="/mrl/js/main.js"></script>

<!-- search -->

<!-- Baidu Analytics -->

<!-- Cloudflare Analytics -->

<!-- Disqus Comments -->

<!-- utterances Comments -->

    </body>

    </html>